﻿using CollegeSim.CourseScheduler.Presentation.Facade;
using System;
using System.Windows.Forms;
using CollegeSim.Domain;
using CollegeSim.Domain.Services;
using CollegeSim.Persistence;
using CollegeSim.Persistence.Repositories;

namespace CollegeSim.CourseScheduler.Presentation
{
    static class Program
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main()
        {
            try
            {
                StartConfig();
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);
                Application.Run(
                    new FormMainMenu(new SchedulerFacade(new CourseService(new CourseRepository()),
                        new InstructorService(new InstructorRepository()))));
            }
            catch (InvalidOperationException ex) // Catch database error
            {
                MessageBox.Show(ex.Message, "Network Error");
                Application.Exit();
            }

        }

        /// <summary>
        /// Create type maps resource libraries.
        /// </summary>
        private static void StartConfig()
        {
            PersistenceMapConfig.Intialize();
            DomainMapConfig.Initialize();
        }
    }
}
